package com.geeklei.media.ui;

import com.geeklei.media.ui.common.ErrorEvent;
import com.geeklei.videoplayer.GeekleiVideoView;

import java.util.ArrayList;
import java.util.List;

public class VideoCycleManager implements IVideoLifeCycle {
    List<IVideoLifeCycle> mQueue = new ArrayList();

    public void add(IVideoLifeCycle iVideoLifeCycle) {
        if (iVideoLifeCycle != null && !this.mQueue.contains(iVideoLifeCycle)) {
            this.mQueue.add(iVideoLifeCycle);
        }
    }

    public void remove(IVideoLifeCycle iVideoLifeCycle) {
        if (iVideoLifeCycle != null && this.mQueue.contains(iVideoLifeCycle)) {
            this.mQueue.remove(iVideoLifeCycle);
        }
    }

    public void onCompletion(GeekleiVideoView iVideoView) {
        for (IVideoLifeCycle onCompletion : this.mQueue) {
            onCompletion.onCompletion(iVideoView);
        }
    }

    public void onPrepared(GeekleiVideoView iVideoView) {
        for (IVideoLifeCycle onPrepared : this.mQueue) {
            onPrepared.onPrepared(iVideoView);
        }
    }

    public void onBufferingStart(GeekleiVideoView iVideoView) {
        for (IVideoLifeCycle onBufferingStart : this.mQueue) {
            onBufferingStart.onBufferingStart(iVideoView);
        }
    }

    public void onBufferingEnd(GeekleiVideoView iVideoView) {
        for (IVideoLifeCycle onBufferingEnd : this.mQueue) {
            onBufferingEnd.onBufferingEnd(iVideoView);
        }
    }

    public void onVideoLoadingStart(GeekleiVideoView iVideoView) {
        for (IVideoLifeCycle onVideoLoadingStart : this.mQueue) {
            onVideoLoadingStart.onVideoLoadingStart(iVideoView);
        }
    }

    public void onBufferingPercent(GeekleiVideoView iVideoView, int i) {
        for (IVideoLifeCycle onBufferingPercent : this.mQueue) {
            onBufferingPercent.onBufferingPercent(iVideoView, i);
        }
    }

    public void onEpLoadingStart() {
        for (IVideoLifeCycle onEpLoadingStart : this.mQueue) {
            onEpLoadingStart.onEpLoadingStart();
        }
    }

    public void onAdsPlayStart(GeekleiVideoView iVideoView) {
        for (IVideoLifeCycle onAdsPlayStart : this.mQueue) {
            onAdsPlayStart.onAdsPlayStart(iVideoView);
        }
    }

    @Override
    public void onInfoListener(GeekleiVideoView iVideoView, int what, int extras) {
        for(IVideoLifeCycle onAdsPlayEnd:this.mQueue){
            onAdsPlayEnd.onInfoListener(iVideoView,what,extras);
        }
    }

    public void onAdsPlayEnd(GeekleiVideoView iVideoView) {
        for (IVideoLifeCycle onAdsPlayEnd : this.mQueue) {
            onAdsPlayEnd.onAdsPlayEnd(iVideoView);
        }
    }

    public void onError(GeekleiVideoView iVideoView,int what ,int extras,ErrorEvent errorEvent){
        for (IVideoLifeCycle t:this.mQueue){
            t.onError(iVideoView,what,extras,errorEvent);
        }
    }

}
